package com.zb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhs
 * @create 2020-07-24-17:42
 */
@RestController
@RequestMapping(value = "/redis")
public class RedisController {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    /**
     * 设置值
     * @param name
     * @return
     */
    @RequestMapping(value = "/setRedis")
    public String setRedis(String name){
        redisTemplate.opsForValue().set("name",name);
        return "OK";
    }

    @RequestMapping(value = "/getRedis")
    public  String getRedis(){
        return redisTemplate.opsForValue().get("name").toString();
    }
}
